from django.conf.urls import url, include
from .import views
from rest_framework.routers import DefaultRouter, SimpleRouter



urlpatterns = [
    url(r'^books/$', views.BookInfoListViews.as_view()),
    url(r'^books/(?P<pk>\d+)$', views.BookInfoDetailViews.as_view()),

    url(r'^generic_books/$', views.BookBookListGenericAPIViewList.as_view()),
    url(r'^generic_books/(?P<pk>\d+)/$', views.BookBookDetailGenericAPIViewList.as_view()),

    url(r'^mixin_books/$', views.BookBookListMixinGenericAPIViewList.as_view()),
    url(r'^mixin_books/(?P<pk>\d+)/$', views.BookBookDetailtMixinGenericAPIViewList.as_view()),

    url(r'^three_books/$', views.BookListThreeView.as_view()),
    url(r'^three_books/(?P<pk>\d+)/$', views.BookDetailThreeView.as_view()),


    url(r'^viewset_book/$', views.BookViewSet.as_view({"get": "list"})),
    url(r'^viewset_book/(?P<pk>\d+)/$', views.BookViewSet.as_view({"get": "retrieve"})),

    url(r'^readonly_book/$', views.BookReadOnlyViewSet.as_view({"get": "list"})),
    url(r'^readonly_book/(?P<pk>\d+)/$', views.BookReadOnlyViewSet.as_view({"get": "retrieve"})),

    url(r'^model_book/$', views.BookModelViewSet.as_view({"get": "list", "post": "create"})),
    url(r'^model_book/(?P<pk>\d+)/$', views.BookModelViewSet.as_view({"get": "retrieve", "put":"update","delete": "destroy"})),

    url(r'^haha/$', views.BookModelViewSet.as_view({"get": "haha"})),

    url(r'^up_data/(?P<pk>\d+)/$', views.BookModelViewSet.as_view({"put": "up_data_bread"})),

]



# 1,创建路由对象                  # 自动生成路由只对视图集有用
router = DefaultRouter()
# router = SimpleRouter()

# 2,注册视图集
router.register(r'auto_book', views.BookModelViewSet, base_name="xixi")

# 3,添加视图集路由到urlpatterns中
urlpatterns += router.urls

print(router.urls)


